<template>
	<div>
		<el-form :inline="true">
			<el-form-item>
				<el-select v-model="searchForm.verifyStatus" placeholder="审核状态" clearable>
					<el-option label="未更新" value="WAIT"></el-option>
					<el-option label="已更新" value="PASS"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button @click="getList">搜索</el-button>
			</el-form-item>

			<el-form-item>
				<el-popconfirm title="这是确定批量删除吗？" @confirm="delHandle(null)">
					<el-button 
            type="danger" 
            slot="reference" 
            :disabled="delBtlStatu" 
            v-if="hasAuth('boat:price:shipTypePrice:delete')">
            批量删除
          </el-button>
				</el-popconfirm>
			</el-form-item>
		</el-form>

		<el-table
			ref="shipPriceTable"
			:data="tableData"
			tooltip-effect="dark"
			style="width: 100%"
			border
			stripe
			@selection-change="handleSelectionChange"
		>
			<el-table-column align="center" fixed="left" type="selection" width="55"> </el-table-column>
			<el-table-column prop="date" fixed="left" align="center" width="100" label="时间"></el-table-column>
			<el-table-column prop="ninevlgc" width="90" align="center" label="9万方VLGC"> </el-table-column>
			<el-table-column prop="sevenpointfivedwt" width="90" align="center" label="7.5万DWT巴拿马型油船"> </el-table-column>
			<el-table-column align="center" width="90" prop="seventhousandteu" label="7000TEU箱船"> </el-table-column>
      <el-table-column align="center" width="90" prop="elevendwt" label="11万DWT阿芙拉型油船"> </el-table-column>
      <el-table-column align="center" width="90" prop="fifteendwt" label="15万DWT苏伊士型油船"> </el-table-column>
      <el-table-column align="center" width="90" prop="thirtytwodwt" label="32万DWT-VCLL"> </el-table-column>
      <el-table-column align="center" width="90" prop="eightpointtwodwt" label="8.2万DWT巴拿马型散货船"> </el-table-column>
      <el-table-column align="center" width="90" prop="fivedwt" label="5万DWT成品油船"> </el-table-column>
      <el-table-column align="center" width="90" prop="threethousandteu" label="3000TEU箱船"> </el-table-column>
      <el-table-column align="center" width="90" prop="seventeenpointfourlng" label="17.4万方LNG运输船"> </el-table-column>
      <el-table-column align="center" width="90" prop="twopointfourteu" label="2.4万TEU箱船"> </el-table-column>
      <el-table-column align="center" width="90" prop="twentyonedwt" label="21万DWT纽卡斯尔型散货船"> </el-table-column>
      <el-table-column align="center" width="90" prop="onepointfiveteu" label="1.5万TEU箱船"> </el-table-column>
      <el-table-column align="center" width="90" prop="seventhousandpcc" label="7000车PCC"> </el-table-column>
      <el-table-column align="center" width="90" prop="eighteendwt" label="18万DWT散货船"> </el-table-column>

			<el-table-column prop="verify_status" align="center" width="100" label="状态">
				<template slot-scope="scope">
					<el-tag v-if="scope.row.verify_status === 'PASS'" type="success"><i class="el-icon-success"></i> 已更新</el-tag>
					<el-tag v-else type="info">未更新</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="update_time" align="center" width="200" label="修改时间"> </el-table-column>
			<el-table-column prop="update_by" align="center" label="修改人"> </el-table-column>
			<el-table-column prop="icon" align="center" fixed="right" width="180px" label="操作">
				<template slot-scope="scope">
					<el-button
						type="primary"
						plain
						@click="addUpdateButton(scope.row.id)"
						v-if="hasAuth('boat:price:shipTypePrice:edit')"
						>编辑</el-button
					>
					<template v-if="hasAuth('boat:price:shipTypePrice:delete')">
						<el-popconfirm title="这是一段内容确定删除吗？" @confirm="delHandle(scope.row.id)">
							<el-button type="danger" plain slot="reference">删除</el-button>
						</el-popconfirm>
					</template>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
			layout="total, sizes, prev, pager, next, jumper"
			:page-sizes="[10, 20, 50, 100]"
			:current-page="current"
			:page-size="size"
			:total="total"
		>
		</el-pagination>
		<AddAndUpdate ref="shipPriceAddUpdate" v-if="addUpdateVisible" @refreshDataList="getList" :type="type"></AddAndUpdate>
	</div>
</template>

<script>
import {formatServerDate, monthFormatStr} from '@/utils/date';
import AddAndUpdate from './AddAndUpdate.vue';
import { typeNameMixin } from '@/mixins/typeName';
import { reportDataListMixin } from '@/mixins/reportDataList';

export default {
	name: 'shipTypePrice',
	components: {
		AddAndUpdate
	},
	props: {
		type: {
			type: String,
			default: '1',
		}
	},
	data() {
		return {
			searchForm: {
				type: this.type
      },
			delBtlStatu: true,
      multipleSelection:[],
			tableData: [],
			total: 0,
			size: 10,
			current: 1,
			addUpdateVisible: false
		};
	},
	mixins: [typeNameMixin, reportDataListMixin],
	mounted() {
		this.getList();
	},
	methods: {
		toggleSelection(rows) {
			if (rows) {
				rows.forEach((row) => {
					this.$refs.shipPriceTable.toggleRowSelection(row);
				});
			} else {
				this.$refs.shipPriceTable.clearSelection();
			}
		},
		handleSelectionChange(val) {
			console.log('勾选');
			console.log(val);
			this.multipleSelection = val;

			this.delBtlStatu = val.length == 0;
		},
		handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
			this.size = val;
			this.getList();
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
			this.current = val;
			this.getList();
		},
		getList() {
      const formData = this.searchForm;
			this.$axios
				.get('/admin/boat/ship/pricetype/list', {
					params: {
						current: this.current,
						size: this.size,
            ...formData,
					},
				})
				.then((res) => {
          const result = res.result;
					this.size = result.size;
					this.current = result.current;
					this.total = result.total;

					return result.records.map((item) => {
            const {create_time, update_time, date, ...rest} = item;

            return {
                create_time: formatServerDate(create_time),
                update_time: formatServerDate(update_time),
                date: formatServerDate(date, monthFormatStr),
                ...rest,
            }
          });
				}).then((list) => {
					return this.addTypeNameCnName(list, {reportDate: this.searchForm.reportDate, type: '1'})
            .then((list) => {
              this.tableData = list
            }); 
				}).catch((e) => {
            console.log(e);
        });  
		},
		delHandle(id) {
			var ids = [];

			if (id) {
				ids.push(id);
			} else {
				this.multipleSelection.forEach((row) => {
					ids.push(row.id);
				});
			}

			this.$axios.get('/admin/boat/ship/pricetype/delByIds', {params:{ids: ids.join(',')}}).then((res) => {
				this.$message({
					showClose: true,
					message: '恭喜你，操作成功',
					type: 'success',
					onClose: () => {
						this.getList();
					},
				});
			});
		},
		addUpdateButton(id) {
			this.addUpdateVisible = true;
			this.$nextTick(() => {
				this.$refs.shipPriceAddUpdate.init(id);
			});
		},
	},
};
</script>

<style scoped>
.el-button {
	padding: 0 10px;
	height: 30px;
	line-height: 30px;
	font-size: 12px;
	margin-right: 10px;
}
</style>
